package com.eagle.view.activity.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.eagle.data.bean.LiveMessage;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

/**
 * Created by gc on 2016/12/31.
 */
@EBean
public class MessageAdapter extends RecyclerViewAdapterBase<LiveMessage, MessageItemView> {

    @RootContext
    protected Context mContext;

    @Override
    protected MessageItemView onCreateItemView(ViewGroup parent, int viewType) {
        return MessageItemView_.build(mContext);
    }

    @Override
    public void onBindViewHolder(ViewWrapper<MessageItemView> holder, int position) {
        MessageItemView view = holder.getView();
        LiveMessage message = items.get(position);
        view.bind(message);
    }

    public void addMessage(LiveMessage msg) {
        if (msg != null) {
            items.add(items.size(), msg);
            notifyDataSetChanged();
        }
    }
}
